package com.ws.shop.action.admin;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ws.shop.bean.Page;
import com.ws.shop.entity.Sunpic;
import com.ws.shop.service.SunpicService;
import com.ws.shop.util.DateUtil;
import com.ws.shop.util.RequestUtil;

@Controller
@RequestMapping(value="/admin/sunpic/*")
public class SunpicAction extends BaseAdminAction{
	private static Logger log = Logger.getLogger(SunpicAction.class);
	@Autowired
	private SunpicService sunpicService = null;
	
	@RequestMapping(value="index.jhtml",method=RequestMethod.GET)
	public String index(HttpServletRequest request,Model model){
		String start = RequestUtil.getStringParameter(request, "start", null);
		String end = RequestUtil.getStringParameter(request, "end", null);
		String q_name = RequestUtil.getStringParameter(request, "q_name", null);
		int q_aid = RequestUtil.getIntParameter(request, "q_aid", 0);
		int pageno = RequestUtil.getIntParameter(request, Page.PAGE_NO, 1);
		if(start == null){
			start = DateUtil.dateToString(new Date(),DateUtil.YYYY_MM_DD);
		}
		if(end == null){
			end = DateUtil.dateToString(new Date(),DateUtil.YYYY_MM_DD);
		}
		Page page = sunpicService.findListByPage(pageno,20,q_name,q_aid,start,end);
		model.addAttribute(Page.PAGE, page);
		model.addAttribute("start", start);
		model.addAttribute("end", end);
		model.addAttribute("q_name", q_name);
		model.addAttribute("q_aid", q_aid);
		model.addAttribute("stateDescs", Sunpic.STATE_DESCS);
		return "sunpic_index";
	}

//	public String view(HttpServletRequest request,Model model){
//		int id = RequestUtil.getIntParameter(request, "id", 0);
//		
//	}
//	
//	public function view(){
//		$id     = GetNum($_GET['id']);		
//		$accessory_relation = M('Accessory_relation');
//		$prefix = C('DB_PREFIX');
//		$accessorydata = $accessory_relation->Table("{$prefix}accessory_relation as A")->
//					  join("{$prefix}accessory as B ON A.accessoryid = B.id")->
//					  field('B.*')->
//					  where("A.relationid = {$id} and A.table = 'Sunpic'")->
//					  findAll();
//		$sunpic = D('Sunpic');
//		$sunpicmap['id']=array('eq',$id);
//		$sunpicdata = $sunpic->where($sunpicmap)->find();
//		$this->assign('data',$accessorydata);
//		$this->assign('sunpicdata',$sunpicdata);
//		$this->display();
//	}
//	
//	public function edit(){
//		$id     = GetNum($_GET['id']);		
//		$sunpic = D('Sunpic');
//		$prefix = C('DB_PREFIX');
//		$sunpicdata = $sunpic->Table("{$prefix}sunpic as S")->
//					  join("{$prefix}auction as A ON S.aid = A.id")->
//					  field('S.*,A.goodsname')->
//					  where("S.id = {$id}")->
//					  findAll();
//		$data = $sunpicdata[0];
//		$this->assign('data',$data);
//		$this->display();	
//	}
//	
//	public function update(){
//		$data = Init_GP(array('comments','state','reward'));
//		$id = GetNum($_POST['id']);
//		$sunpic = D('Sunpic');
//		$sunpicdata = $sunpic->find($id);
//		$map['id']=array('eq',$id);
//		$reward = GetNum($data['reward']);
//		
//		if(!empty($reward) && !empty($sunpicdata)){
//			$user = D('User');
//			$config = C('SYSCONFIG');
//			$transaction = D('Transaction');
//			$transactiondata = array(
//				'uid'=>$sunpicdata['uid'],
//				'name' =>$sunpicdata['name'],
//				'payment'=>'晒图奖励',
//				'money'=>$reward,
//				'addtime'=>time(),
//				'remark'=>"晒图奖励{$reward}{$config['pointb_name']}"
//			);
//			$transaction->add($transactiondata);
//			$user->setInc('pointb',"id={$sunpicdata['uid']}",$reward);
//			$data['reward'] = $reward;			
//		}else{
//			unset($data['reward']);
//		}
//
//		parent::update($data,$map);
//	}
	
}
